<?php
include("conn/conn.php");
include("header.php");

$where = "";

$typeid = $_GET['typeid'];
if($typeid){
	$where.=" where typeid='$typeid' ";
}
?>

	         
<div id="content" class="ersee_product_height_ie6" style="position: relative;">
	<!-- 左侧菜单栏 -->
	 <!-- 左侧菜单栏 -->
 
<?php include("left2.php");?>

	
<!-- 公告 wanglei 20130401-->
<div id="s_nt" class="notice s_nt" >
  <div class="news">&gt;最新活动：</div>
  <div id="rolling">
  <?php
   $sql_showgg=mysql_query("select * from tb_gonggao order by time desc limit 10",$conn);
	$info_showgg=mysql_fetch_array($sql_showgg);

	while($info_showgg=mysql_fetch_array($sql_showgg)){
  ?>
  	
  		<p rtype="2" cid="0" >
  		   <a looyu_bound="1" target="_blank" href="news_info.php?id=<?php echo $info_showgg[id];?>" > 
  				<?php echo $info_showgg[title]; ?>
  		   	&nbsp; 
  		   	
  			
  				<img src="kfc_files/new.png">
  			
  			<span>查看详情»</span>
  		   </a> 
		</p>
  		
 <?php }  ?>	
  

  </div>
</div>


	<!-- 详细内容部分 -->
	<div id="main" class="e_main">

		<!--  -->
		<div class="home_bg_mid" style="margin:3px 0 0;min-height:520px;">
			<div class="prod_show" style="">
				
<?php 

	$sql_jr=mysql_query("select count(*) as total from tb_shangpin ".$where." ",$conn);
	   $info_jr=mysql_fetch_array($sql_jr);
	   $total=$info_jr[total];
	   if($total==0){
	     echo "暂无";
	   }
	   else
	    { ?>
			<ul class="product_ul">
		<?php
	    	$pagesize=6;
		   if ($total<=$pagesize){
		      $pagecount=1;
			} 
			if(($total%$pagesize)!=0){
			   $pagecount=intval($total/$pagesize)+1;
			}else{
			   $pagecount=$total/$pagesize;
			}
			if(($_GET[page])==""){
			    $page=1;
			}else{
			    $page=intval($_GET[page]);
			}
           $sql1=mysql_query("select * from tb_shangpin ".$where." order by addtime desc limit ".($page-1)*$pagesize.",$pagesize",$conn);
		   while($info1=mysql_fetch_array($sql1))
		    {
	

?>

					<li>
						<div href="javascript:;" class="showPicPop" id="<?php echo $info1['id']; ?>">
							<img src="<?php echo "".$info1[tupian];?>">
						</div>
						<div class="pro_info">
							<p><a href="javascript:;" class="pro_name"><?php echo $info1[mingcheng];?></a></p>
							<p>
								<span class="pro_price"><?php echo $info1[shichangjia];?>元/份 </span>
								<span class="pro_number">
									<a href="javascript:;" onClick="shuliang_minus(<?php echo $info1['id']; ?>);">
										<img src="kfc_files/minus_icon_2.gif">
									</a>
									<input class="pro_number_input" id="total_<?php echo $info1['id']; ?>" value="1" maxlength="2" type="text"/>
									<a href="javascript:;" onClick="shuliang_add(<?php echo $info1['id']; ?>);" ><img src="kfc_files/add_icon_002.gif"></a>
								</span>
							</p>
							<p class="p_clear_both"><input id="<?php echo $info1['id']; ?>" class="order_btn" type="button"></p>
						</div>
					</li>
			<?php }?>


				</ul>
	<?php }?>
			</div>

		</div>
<!-- 页码开始 -->
<?php if($pagecount>1){ ?>
<div class="page_nav">

        <?php
		  if($page>=2)
		  {
		  ?>
        <a href="shopping.php?typeid=<?php echo $typeid;?>&page=1" title="首页"><font size="2">首页</font></a> <a href="shopping.php?typeid=<?php echo $typeid;?>&page=<?php echo $page-1;?>" title="前一页"><font size="2">前一页</font></a>
        <?php
		  }
		   if($pagecount<=4){
		    for($i=1;$i<=$pagecount;$i++){
		  ?>
        <a href="shopping.php?typeid=<?php echo $typeid;?>&page=<?php echo $i;?>" <?php echo $page==$i? 'class="cur_page"': ''?>><?php echo $i;?></a>
        <?php
		     }
		   }else{
		   for($i=1;$i<=4;$i++){	 
		  ?>
        <a href="shopping.php?typeid=<?php echo $typeid;?>&page=<?php echo $i;?>"  <?php echo $page==$i? 'class="cur_page"': ''?>><?php echo $i;?></a>
        <?php }?>
        <a href="shopping.php?typeid=<?php echo $typeid;?>&page=<?php echo $page+1;?>" title="下一页"><font size="2">下一页</font></a> <a href="shopping.php?typeid=<?php echo $typeid;?>&page=<?php echo $pagecount;?>" title="尾页"><font size="2">尾页</font></a>
        <?php }?>
</div>
<?php } ?>
<!-- 页码结束 -->
		<p class="clear"></p>
	</div>

	<!-- 右侧模块  modified by Pete-->
	
		
			<div id="s_cart" class="right s_rm_cart" style="position: absolute; top:0; float:none; margin: 0 0 0 779px;">
				<div id="shopping_cart">
					<!-- 在线客服 -->
					
<!-- 右侧订单 -->
					<?php include("right.php");?>

<div class="help">
	<div class="index_ocontent">
		本店送实行专属菜单及价格。为了保证食物品质，本店有送餐范围和服务时间限制。不同城市、不同送餐范围的菜单有所不同。不同时段产品品项及价格有所不同。详情以输入送餐地址后显示的菜单为准。不设最低起送金额。
		<br>
		
	</div>

</div>
				</div>
			</div>
		
		
	

	<div class="clear"></div>
</div>
<div id="popup_dialog" style="display:none;">
	<div class="popup_top"></div>
	<div class="popup_main">
		<p class="close_icon"><a class="close_pop"><img src="images/close_icon.png"></a></p>
		<div style="padding:10px;" id="popup_product_detail">
		
		</div>
	</div>
	<div class="popup_btm"></div>
</div>

<script type="text/javascript">

function shuliang_add(id){
	var total = Number($('#total_'+id).val());
	$('#total_'+id).val(total+1);
}
function shuliang_minus(id){
	var total = Number($('#total_'+id).val());
	var t= total-1;
	if(t<1) t=1;
	$('#total_'+id).val(t);

}

$(function(){

	$('.order_btn').click(function(){
	
		var id = $(this).attr('id');
		
		//alert(n.toFixed(1));

		var total = Number($('#total_'+id).val());

		 $.ajax({
					type: "post",
					dataType: "json",
					url: "shopping/add_cart.php",
					data: {"id":id,"total":total},
					success: function(data){
						console.log(data);
						if(data.error=='2'){
							window.location.href='orderlogin.php';
							return false;
						}
						
						if(data.error=='1'){
							alert(data.msg);
						} else {
							$("#order_detail").append(data.msg);
							$('#order_price').html(data.total);
						}
				}
			});
	});

	$('.showPicPop').click(function(){
		
		var id = $(this).attr('id');

		 $.ajax({
					type: "post",
					dataType: "json",
					url: "ajax/item_detail.php",
					data: {"id":id},
					success: function(data){
						$('#popup_product_detail').html(data.html);
						$('#popup_dialog').bPopup({closeClass:'close_pop'});
				}
			});

		
		
	});
	

});



//滚动新闻
$(function(){
	var scrtime;
	 $("#rolling").hover(function(){
			clearInterval(scrtime);
	
	},function(){
	
	scrtime = setInterval(function(){
			var $ul = $("#rolling");
			var liHeight = $ul.find("p:last").height();
			$ul.animate({marginTop : liHeight+30 +"px"},1000,function(){
			
			$ul.find("p:last").prependTo($ul)
			$ul.find("p:first").hide();
			$ul.css({marginTop:0});
			$ul.find("p:first").fadeIn(2000);
			});        
	},3000);
	
	}).trigger("mouseleave");        
        
}); 
</script>

<?php include("footer.php");?>